home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12681 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  48 lines

  1. Path: alpha2.csd.uwm.edu!peterk
  2. From: peterk@alpha2.csd.uwm.edu (Peter J Kleczka)
  3. Newsgroups: comp.lang.c
  4. Subject: Weird Results with this code
  5. Date: 2 Apr 1996 06:44:20 GMT
  6. Organization: Information & Media Technologies, University of Wisconsin - Milwaukee
  7.     I am trying to learn C and ran into a little snag.
  8. Distribution: world
  9. Message-ID: <4jqic4$jg7@uwm.edu>
  10. NNTP-Posting-Host: 129.89.169.2
  11.  
  12. The program is supposed to display
  13. some digits leave them on the screen for a second or so
  14. and then erase them.  The "bug" is that the program seems
  15. to jump to the timer-loop BEFORE it prints out the digits.
  16. Consequently the desired display/delay/erase sequence works
  17. in the wrong order: delay/display/erase.  
  18.  
  19. thanks in advance for your suggestions
  20. please respond via email: peterk@csd.uwm.edu
  21.  
  22.  
  23. /* Display and Erase */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <time.h>
  27.  
  28. void main()
  29. {
  30.   long now;
  31.   char pause;
  32.  
  33.   now = clock();
  34.   printf ("watch the screen carefully please \n");
  35.   printf("I will print the message: \"123 disappear\"\n");
  36.   printf("then after a short pause\n");
  37.   printf("only the digits \"123\" will disappear\n");
  38.   printf("press return when ready\n");
  39.   scanf ("%c", &pause);
  40.   printf ("123 disappear");
  41.  
  42.   for ( ; clock() - now < CLOCKS_PER_SEC ; );  /* the timer loop */
  43.  
  44.   printf ("\r");
  45.   printf ("   ");
  46.   
  47. }
  48.